package com.fh.controller;

import com.fh.common.ResultEnum;
import com.fh.common.ResultMessage;
import com.fh.model.TUser;
import com.fh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@RequestMapping("/")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/login")
    public ResultMessage loginUser(String userNickname, String userPwd){
        //判断用户名和密码是否为空
        if(StringUtils.isEmpty(userNickname)|| StringUtils.isEmpty(userPwd)){
            return new ResultMessage(ResultEnum.LOGIN_ERROR1);
        }


        Map<String,Object>map=new HashMap<String,Object>();
        map.put("userNickname",userNickname);
        map.put("userPwd",userPwd);


        TUser tUser = userService.selectByNameAndPassword(map);

        //判断用户是否为空
        if(tUser==null){
            return new ResultMessage(ResultEnum.LOGIN_ERROR3);
        }

        return new ResultMessage(ResultEnum.QUERY_SUCCESS,tUser);

    }
}
